 $(document).ready(function() {
             //		权限判断
		if($.cookie('ID') == null){
			window.location.href="http://www.duoweish.com/crm/login.html";
		}
//		2，3号权限
		if($.cookie('Right') == 1){
			window.location.href="http://www.duoweish.com/crm/index.html";
		}
 	
			  var page_num = 0;		
             
             Ajax(1);
            $('.dw_name').text($.cookie('Name'));
		    $('.dw_part').text($.cookie('Department'));
          
            function Ajax(curr){
            
			
				
            	$.ajax({
				headers:{
				    	Accept:"application/json;charset=utf-8"
				    },
					type:"get",
					url:"http://www.duoweish.com/apis/EventApprove/",
					data:{
                           page:curr||1,
					     	rows:8,
						  UserId:$.cookie('ID')
					},
					success:function(data){
							page_num = data[1];
							tableData(data);
							divePage(page_num,curr);
							
						}
				})
            	
            }
            
            function tableData(ret){
                    $('#table_body').empty();
                    
                    for(var i = 0;i < ret.length;i++){
                    	for (var j = 0;j<ret[i].length;j++) {
                    		
                    	if(ret[i][j][6]==undefined){
                    		ret[i][j][6]='此次更新没有备注';
                    	}
                        var tr = `<tr>
                                <td style="line-height:20px;">${ret[i][j][0]}</td>
                                <td style="line-height:20px;"><a class="user_btn" cstm="${ret[i][j][6]}">${ret[i][j][1]}<a></td>
                                <td style="line-height:20px;">${ret[i][j][2]}</td>
                                <td style="line-height:20px;">${ret[i][j][3]}</td>
                                <td style="line-heightL20px">${ret[i][j][4]}</td>
                                <td  index="${ret[i][j][5]}">
                                      <button class="look_btn1">查看</button>
                                </td>
                                <td index="${ret[i][j][5]}">
                                	<button class="look_btn2">点赞</button>
                                	
                                </td>
                               
                            </tr>`;
                        $('#table_body').append(tr);
                    }
                }
                   
                   $('.user_btn').click(function(){
                   	  var cstmId = $(this).attr("cstm");
                         	layer.open({
									        type: 2
									        ,closeBtn: 1
									        ,area:['1366px','700px']
									        ,shade: 0.8
									        ,shadeClose:true
									        ,btnAlign: 'c'
									        ,moveType: 1 
									        ,content:'http://www.duoweish.com/crm/user_infor.html?Id_data='+cstmId
										    ,success: function(){
										    	
							          	}
							    	 })
                   })
                   
                    $('.look_btn2').click(function(){
                    	var Id_data = $(this).parent().attr('index');
						$.ajax({
							type:"get",
							url:"http://www.duoweish.com/apis/EventPraise/",
							data:{
								Event:Id_data
							},
							success:function(){
								layer.msg('点赞成功');
								$('#table_body').html("");
								Ajax(1);
							}
						})
                    })
                   $('.look_btn1').click(function(){
                 	    var id_data = $(this).parent().attr("index");
								     layer.open({
									        type: 2
									        ,anim:1
									        ,title: false
									        ,closeBtn: 1
									        ,shade: 0.5
									        ,shadeClose:true
									        ,area:'600px'
									        ,id:'my_open'
									        ,scrollbar:false
									        ,btnAlign: 'c'
									        ,moveType: 1 
									        ,content:'http://www.duoweish.com/crm/open_event.html?data_id='+id_data
										    ,success: function(index){
										    	setTimeout(function(){
										    		var new_H=$('#my_open').find("iframe").contents().find("#now_event").height()+3;
										    		console.log(new_H)
										    		$("#my_open").find("iframe").css('height',new_H+'px');
										    	},200)
										    	
										    	
										    	     
							          	  }
							    	 })	
						  
                      })
                  
             
                    
            }
           function divePage(page_num,curr){
            layui.use(['laypage', 'layer'], function(){
					 var laypage = layui.laypage
			  		,layer = layui.layer;
                     laypage.render({
						    elem: 'demo0'
						    ,count: page_num
						    ,curr:curr
						    ,jump: function(obj, first){
						    	   if(!first){
						                Ajax(obj.curr);
						               }
				        
						      		}
						   		});
					 })		
           }
          
          
     
           
})